home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 8
/
QRZ Ham Radio Callsign Database - Volume 8.iso
/
pc
/
files
/
t_unix
/
j109lxa4.tar
/
rwhodump.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-04
|
4KB
|
167 lines
#include <stdio.h>
#include <time.h>
#include "global.h"
#include "mbuf.h"
#include "trace.h"
#ifndef __GNUC__
static
#endif
struct outmp {
char out_line[9]; /* tty name */
char out_name[9]; /* user id */
int32 out_time; /* time on */
};
#ifndef __GNUC__
static
#endif
struct whod {
char wd_vers;
char wd_type;
char wd_fill[2];
int32 wd_sendtime;
int32 wd_recvtime;
char wd_hostname[33];
int32 wd_loadav[3];
int32 wd_boottime;
struct whoent {
struct outmp we_utmp;
int32 we_idle;
} wd_we[1024 / sizeof (struct whoent)];
};
static int ntohrwhod __ARGS((struct whod *wp,struct mbuf **bpp));
void
#ifdef MONITOR
#ifdef PROTOTYPES
rwho_dump(FILE *fp,struct mbuf **bpp,int mon)
#else
rwho_dump(fp,bpp,mon)
#endif
#else
#ifdef PROTOTYPES
rwho_dump(FILE *fp,struct mbuf **bpp)
#else
rwho_dump(fp,bpp)
#endif
FILE *fp;
struct mbuf **bpp;
#ifdef MONITOR
int mon;
#endif
#endif
{
int i;
int32 t;
char *cp;
struct whod rwhod;
if(bpp == NULLBUFP || *bpp == NULLBUF)
return;
#ifdef MONITOR
if (mon)
fprintf(stderr, "RWHO ");
else
#endif
fprintf(fp,"RWHO: ");
if(ntohrwhod(&rwhod,bpp) == -1) {
fprintf(fp,"bad data\n");
return;
}
#ifdef MONITOR
if (!mon)
{
#endif
if(rwhod.wd_vers != 1)
fprintf(fp,"version %d ",rwhod.wd_vers);
if(rwhod.wd_type != 1)
fprintf(fp,"type %d ",rwhod.wd_type);
cp = ctime(&rwhod.wd_sendtime);
cp[24] = '\0';
fprintf(fp,"send %s ",cp);
t = rwhod.wd_recvtime;
if(t / 86400)
fprintf(fp,"%ld:",t/86400);
t %= 86400;
fprintf(fp,"recv %02ld:%02ld\n",t / 3600,(t % 3600)/60);
fprintf(fp," host %s loadvg %ld %ld %ld ",rwhod.wd_hostname,
rwhod.wd_loadav[0],rwhod.wd_loadav[1],
rwhod.wd_loadav[2]);
fprintf(fp,"boot %s",ctime(&rwhod.wd_boottime));
#ifdef MONITOR
}
else
{
fprintf(fp, "%s load %d %d %d\n", rwhod.wd_hostname,
rwhod.wd_loadav[0], rwhod.wd_loadav[1],
rwhod.wd_loadav[2]);
}
#endif
i = 0;
while(rwhod.wd_we[i].we_utmp.out_line[0] != '\0') {
#ifdef MONITOR
if (mon)
{
fprintf(fp, "%-12s%c", rwhod.wd_we[i].we_utmp.out_name,
(i % 5 == 4? '\n': '\t'));
}
else
{
#endif
fprintf(fp," %-12s%-12s",rwhod.wd_we[i].we_utmp.out_name,
rwhod.wd_we[i].we_utmp.out_line);
t = rwhod.wd_we[i].we_idle;
if(t / 86400)
fprintf(fp,"%ld:",t/86400);
else
fprintf(fp," ");
t %= 86400;
fprintf(fp,"%02ld:%02ld ",t / 3600, (t % 3600)/60);
fprintf(fp,"%s",ctime(&rwhod.wd_we[i].we_utmp.out_time));
#ifdef MONITOR
}
#endif
++i;
}
#ifdef MONITOR
if (mon && i % 5)
fprintf(fp, "\n");
#endif
}
static int
ntohrwhod(wp,bpp)
struct whod *wp;
struct mbuf **bpp;
{
int i;
char wbuf[60];
if(pullup(bpp,wbuf,60) != 60)
return -1;
wp->wd_vers = wbuf[0];
wp->wd_type = wbuf[1];
wp->wd_fill[0] = wbuf[2];
wp->wd_fill[1] = wbuf[3];
wp->wd_sendtime = get32(&wbuf[4]);
wp->wd_recvtime = get32(&wbuf[8]);
memcpy(wp->wd_hostname,&wbuf[12],32);
wp->wd_hostname[32] = '\0';
wp->wd_loadav[0] = get32(&wbuf[44]);
wp->wd_loadav[1] = get32(&wbuf[48]);
wp->wd_loadav[2] = get32(&wbuf[52]);
wp->wd_boottime = get32(&wbuf[56]);
for(i = 0; i < 42; ++i) {
if(pullup(bpp,wbuf,24) != 24) {
wp->wd_we[i].we_utmp.out_line[0] = '\0';
return 0;
}
memcpy(wp->wd_we[i].we_utmp.out_line,wbuf,8);
wp->wd_we[i].we_utmp.out_line[8] = '\0';
memcpy(wp->wd_we[i].we_utmp.out_name,&wbuf[8],8);
wp->wd_we[i].we_utmp.out_name[8] = '\0';
wp->wd_we[i].we_utmp.out_time = get32(&wbuf[16]);
wp->wd_we[i].we_idle = get32(&wbuf[20]);
}
return 0;
}